import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
// import Login from '@/components/Login'

Vue.use(Router)


// 解决报错
const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace
// push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}


export default new Router({
  routes: [
    {
      path: '/helloWorld',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/login',
      name: 'Login',
      // component: Login
      component: () => import('../views/Login.vue') //按需加载
    },
    {
      path: '/index',
      name: 'Index',
      component: () => import('../views/Index.vue'),
      children: [
        {
          path: 'userList',
          name: 'UserList',
          component: () => import('../views/user/UserList.vue'),
        },
        {
          path: 'deptList',
          name: 'DeptList',
          component: () => import('../views/dept/DeptList.vue'),
        },
        {
          path: 'orderList',
          name: 'OrderList',
          component: () => import('../views/order/OrderList.vue'),
        }
      ]
    },
    {
      path: '*',
      component: () => import('../views/404.vue') //按需加载
    },
  ]
})
